﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_addnew : System.Web.UI.Page
{
    News n = new News();
    Class c=new Class();

    protected void Page_Load(object sender, EventArgs e)
    {
        Function.CheckSession();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.File1.PostedFile != null)
        {
            string filename = File1.PostedFile.FileName;
            int i = filename.LastIndexOf(".");//获取文件名中最后一个.的索引位置
            string ex_name = filename.Substring(i);
            if (ex_name.ToUpper() != ".GIF" && ex_name.ToUpper() != ".JPG" && ex_name.ToUpper() != ".JPEG")
            {
                Response.Write("<scirpt>alert('文件格式不正确，请选择 jpg 或者 gif 格式的图片！');</script>");
                Response.End();
            }
            DateTime now = DateTime.Now;//获取当前时间
            string savefilename = now.Millisecond.ToString() + "_" + File1.PostedFile.ContentLength.ToString() + ex_name;
            File1.PostedFile.SaveAs(Server.MapPath("upload_pic/" + savefilename));
            this.Image1.Visible = true;
            this.Image1.ImageUrl = "upload_pic/" + savefilename;
            Response.Write("<script>alert('上传成功');</script>");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        //string classname=Request.Form["Text1"].Replace("├","").Trim();
        int classid = int.Parse(Request.Form["parentid"]);
        //Response.Write(classname);
        //int classid = Convert.ToInt32(c.GetClassIdByName(classname, parentid));
        n.Classid = classid;
        n.Title = this.TextBox1.Text;
        n.Author = "办公室";
        n.Suggest = 0;
        n.Keyword = this.TextBox2.Text;
        n.Pic = this.Image1.ImageUrl;
        n.Content = this.FCKeditor1.Value;
        if (this.TextBox4.Text == "")
        {
            n.Addtime = DateTime.Now;
        }
        else
        {
            n.Addtime = Convert.ToDateTime(this.TextBox4.Text);
        }
        n.Hit = 0;
        n.Lasttitle = "";
        n.AddNews(n);
        Response.Write("<script> if(confirm('继续添加？'))window.location='addnew.aspx';else window.location='managenews.aspx'</script>");
    }
}
